package com.ss.whisper2.config;

import java.util.concurrent.Executor;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer{

	@Override
	@Bean
	public Executor getAsyncExecutor() {
		ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
		//核心线程数
		taskExecutor.setCorePoolSize(5);
		//最大线程数
		taskExecutor.setMaxPoolSize(10);
		//缓冲队列长度
		taskExecutor.setQueueCapacity(25);
		//等待任务在关机时完成--表明等待所有线程执行完
		//taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
		// 等待时间 （默认为0，此时立即停止），并没等待xx秒后强制停止
		taskExecutor.setAwaitTerminationSeconds(60);
		//  线程名称前缀
		taskExecutor.setThreadNamePrefix("Whisper2-");
		//初始化
		taskExecutor.initialize();
		return taskExecutor;
	}
}